package com.dotstone.chipism.bean;

import java.util.ArrayList;
import java.util.List;

import com.dotstone.chipism.util.ConvertUtil;
import com.dotstone.chipism.util.Util;

import android.util.Log;

public class Cmd_Open {
	private String mainDeviceId;
	private String openCmdlinghuo="";
	private String openCmdlinghuo2="";
	private String openCmdlinghuo3="";
	private String openCmdcurtain="";
	private String openCmdss="";
	private String openCmdl="";
	private List<Device> linghuoDevices;
	private List<Device> linghuoDevices2;
	private List<Device> linghuoDevices3;
	private List<Device> curtainDevices;
	private List<Device> mSSDevices;
	private List<Device> mLightDevices;
	private List<String> mLinghuoaddress = new ArrayList<String>();
	private List<String> mLinghuoaddress2 = new ArrayList<String>();
	private List<String> mLinghuoaddress3 = new ArrayList<String>();
	private List<String> mCurtainddress = new ArrayList<String>();
	private List<String> mLightAddress = new ArrayList<String>();
	private List<String> mSwitchAddress = new ArrayList<String>();
	private int[] intOpenLinghuoAdds;
	private int[] intOpenLinghuoAdds2;
	private int[] intOpenLinghuoAdds3;
	private int[] intOpenCurtainAdds;
	private int[] intOpenSwitchAdds;
	private int[] intOpenLightAdds;
	private byte[] byteLinghuoAdds;
	private byte[] byteLinghuoAdds2;
	private byte[] byteLinghuoAdds3;
	private byte[] byteCurtainAdds;
	private byte[] byteSocketAdds;
	private byte[] byteLightAdds;
	private int[] intLLH = new int[5];
	private int[] intLLH2= new int[5];
	private int[] intLLH3 = new int[5];
	private int[] intLC = new int[5];
	private int[] intLS = new int[5];
	private int[] intLA = new int[5];
	private String ir_cmd="";
	private String ir_deviceId = "";

	public String getMainDeviceId() {
		return mainDeviceId;
	}

	public void setMainDeviceId(String mainDeviceId) {
		this.mainDeviceId = mainDeviceId;
	}

	public String getIr_cmd() {
		return ir_cmd;
	}

	public void setIr_cmd(String ir_cmd) {
		this.ir_cmd = ir_cmd;
	}

	public Cmd_Open() {

	}

	
	public String getIr_deviceId() {
		return ir_deviceId;
	}

	public void setIr_deviceId(String ir_deviceId) {
		this.ir_deviceId = ir_deviceId;
	}
	public String getOpenCmdCurtain() {
		return openCmdcurtain;
	}

	public String getOpenCmdLinghuo() {
		return openCmdlinghuo;
	}
	public String getOpenCmdLinghuo2() {
		return openCmdlinghuo2;
	}
	public String getOpenCmdLinghuo3() {
		return openCmdlinghuo3;
	}

	public String getOpenCmdss() {
		return openCmdss;
	}

	public String getOpenCmdl() {
		return openCmdl;
	}

	public List<Device> getmSSDevices() {
		return mSSDevices;
	}



	public void setLingHuoDevices(List<Device> linghuoDevices) {
		this.linghuoDevices = linghuoDevices;
		if (linghuoDevices.size() > 0) {
			for (int i = 0; i < linghuoDevices.size(); i++) {
				mLinghuoaddress.add(linghuoDevices.get(i).getDeviceAddress());
			}
			intOpenLinghuoAdds = new int[mLinghuoaddress.size() * 5 + 5];
			intOpenLinghuoAdds[0] = mLinghuoaddress.size();
			intOpenLinghuoAdds[mLinghuoaddress.size() * 5 + 5 - 4] = 17;
			intOpenLinghuoAdds[mLinghuoaddress.size() * 5 + 5 - 3] = 255;
			intOpenLinghuoAdds[mLinghuoaddress.size() * 5 + 5 - 2] = 0;
			intOpenLinghuoAdds[mLinghuoaddress.size() * 5 + 5 - 1] = 0;
			for (int i = 0; i < mLinghuoaddress.size(); i++) {
				byteLinghuoAdds = Util.hexStringToBytes(mLinghuoaddress.get(i));
				intLLH = Util.byte2HexStr1(byteLinghuoAdds);
				for (int j = 0; j < intLLH.length; j++) {
					intOpenLinghuoAdds[i * 5 + 1 + j] = intLLH[j];
				}
			}
			openCmdlinghuo =  ConvertUtil.getInstance().transGroundCmd(intOpenLinghuoAdds,mainDeviceId);
		} else {
			openCmdlinghuo = "";
		}
	}

	public void setLingHuoDevices2(List<Device> linghuoDevices2) {
		this.linghuoDevices2 = linghuoDevices2;
		if (linghuoDevices2.size() > 0) {
			for (int i = 0; i < linghuoDevices2.size(); i++) {
				mLinghuoaddress2.add(linghuoDevices2.get(i).getDeviceAddress());
			}
			intOpenLinghuoAdds2 = new int[mLinghuoaddress2.size() * 5 + 5];
			intOpenLinghuoAdds2[0] = mLinghuoaddress2.size();
			intOpenLinghuoAdds2[mLinghuoaddress2.size() * 5 + 5 - 4] = 18;
			intOpenLinghuoAdds2[mLinghuoaddress2.size() * 5 + 5 - 3] = 255;
			intOpenLinghuoAdds2[mLinghuoaddress2.size() * 5 + 5 - 2] = 0;
			intOpenLinghuoAdds2[mLinghuoaddress2.size() * 5 + 5 - 1] = 0;
			for (int i = 0; i < mLinghuoaddress2.size(); i++) {
				byteLinghuoAdds2 = Util.hexStringToBytes(mLinghuoaddress2.get(i));
				intLLH2= Util.byte2HexStr1(byteLinghuoAdds2);
				for (int j = 0; j < intLLH2.length; j++) {
					intOpenLinghuoAdds2[i * 5 + 1 + j] = intLLH2[j];
				}
			}
			openCmdlinghuo2 =  ConvertUtil.getInstance().transGroundCmd(intOpenLinghuoAdds2,mainDeviceId);
		} else {
			openCmdlinghuo2 = "";
		}
	}

	public void setLingHuoDevices3(List<Device> linghuoDevices3) {
		this.linghuoDevices3 = linghuoDevices3;
		if (linghuoDevices3.size() > 0) {
			for (int i = 0; i < linghuoDevices3.size(); i++) {
				mLinghuoaddress3.add(linghuoDevices3.get(i).getDeviceAddress());
			}
			intOpenLinghuoAdds3 = new int[mLinghuoaddress3.size() * 5 + 5];
			intOpenLinghuoAdds3[0] = mLinghuoaddress3.size();
			intOpenLinghuoAdds3[mLinghuoaddress3.size() * 5 + 5 - 4] = 19;
			intOpenLinghuoAdds3[mLinghuoaddress3.size() * 5 + 5 - 3] = 255;
			intOpenLinghuoAdds3[mLinghuoaddress3.size() * 5 + 5 - 2] = 0;
			intOpenLinghuoAdds3[mLinghuoaddress3.size() * 5 + 5 - 1] = 0;
			for (int i = 0; i < mLinghuoaddress3.size(); i++) {
				byteLinghuoAdds3 = Util.hexStringToBytes(mLinghuoaddress3.get(i));
				intLLH3 = Util.byte2HexStr1(byteLinghuoAdds3);
				for (int j = 0; j < intLLH3.length; j++) {
					intOpenLinghuoAdds3[i * 5 + 1 + j] = intLLH3[j];
				}
			}
			openCmdlinghuo3 =  ConvertUtil.getInstance().transGroundCmd(intOpenLinghuoAdds3,mainDeviceId);
		} else {
			openCmdlinghuo3 = "";
		}
	}


	public void setCurtainDevices(List<Device> curtainDevices) {
		this.curtainDevices = curtainDevices;
		if (curtainDevices.size() > 0) {
			for (int i = 0; i < curtainDevices.size(); i++) {
				mCurtainddress.add(curtainDevices.get(i).getDeviceAddress());
			}
			intOpenCurtainAdds = new int[mCurtainddress.size() * 5 + 5];
			intOpenCurtainAdds[0] = mCurtainddress.size();
			intOpenCurtainAdds[mCurtainddress.size() * 5 + 5 - 4] = 17;
			intOpenCurtainAdds[mCurtainddress.size() * 5 + 5 - 3] = 2;
			intOpenCurtainAdds[mCurtainddress.size() * 5 + 5 - 2] = 0;
			intOpenCurtainAdds[mCurtainddress.size() * 5 + 5 - 1] = 0;
			for (int i = 0; i < mCurtainddress.size(); i++) {
				byteCurtainAdds = Util.hexStringToBytes(mCurtainddress.get(i));
				intLC = Util.byte2HexStr1(byteCurtainAdds);
				for (int j = 0; j < intLC.length; j++) {
					intOpenCurtainAdds[i * 5 + 1 + j] = intLC[j];
				}
			}
			openCmdcurtain =  ConvertUtil.getInstance().transGroundCmd(intOpenCurtainAdds,mainDeviceId);
		} else {
			openCmdcurtain = "";
		}
	}


	public void setmSSDevices(List<Device> mSSDevices) {
		this.mSSDevices = mSSDevices;
		if (mSSDevices.size() > 0) {
			for (int i = 0; i < mSSDevices.size(); i++) {
				mSwitchAddress.add(mSSDevices.get(i).getDeviceAddress());
			}
			intOpenSwitchAdds = new int[mSwitchAddress.size() * 5 + 5];
			intOpenSwitchAdds[0] = mSwitchAddress.size();
			intOpenSwitchAdds[mSwitchAddress.size() * 5 + 5 - 4] = 16;
			intOpenSwitchAdds[mSwitchAddress.size() * 5 + 5 - 3] = 255;
			intOpenSwitchAdds[mSwitchAddress.size() * 5 + 5 - 2] = 0;
			intOpenSwitchAdds[mSwitchAddress.size() * 5 + 5 - 1] = 0;
			for (int i = 0; i < mSwitchAddress.size(); i++) {
				byteSocketAdds = Util.hexStringToBytes(mSwitchAddress.get(i));
				intLS = Util.byte2HexStr1(byteSocketAdds);
				for (int j = 0; j < intLS.length; j++) {
					intOpenSwitchAdds[i * 5 + 1 + j] = intLS[j];
				}
			}
			openCmdss =  ConvertUtil.getInstance().transGroundCmd(intOpenSwitchAdds,mainDeviceId);
		} else {
			openCmdss = "";
		}
	}

	public void setOpenCmdss(String openCmdss) {
		this.openCmdss = openCmdss;
	}

	public List<Device> getmLightDevices() {
		return mLightDevices;
	}

	public void setmLightDevices(List<Device> mLightDevices) {
		this.mLightDevices = mLightDevices;
		Log.i("wmy", "mLightDevices = "+mLightDevices.size());
		if (mLightDevices.size() > 0) {
			for (int i = 0; i < mLightDevices.size(); i++) {
				mLightAddress.add(mLightDevices.get(i).getDeviceAddress());
			}
			intOpenLightAdds = new int[mLightAddress.size() * 5 + 5];
			intOpenLightAdds[0] = mLightAddress.size();
			intOpenLightAdds[mLightAddress.size() * 5 + 5 - 4] = 121;
			intOpenLightAdds[mLightAddress.size() * 5 + 5 - 3] = 255;
			intOpenLightAdds[mLightAddress.size() * 5 + 5 - 2] = 0;
			intOpenLightAdds[mLightAddress.size() * 5 + 5 - 1] = 0;
			for (int i = 0; i < mLightAddress.size(); i++) {
				byteLightAdds = Util.hexStringToBytes(mLightAddress.get(i));
				intLA = Util.byte2HexStr1(byteLightAdds);
				for (int j = 0; j < intLA.length; j++) {
					intOpenLightAdds[i * 5 + 1 + j] = intLA[j];
				}
			}
			openCmdl = ConvertUtil.getInstance().transGroundCmd(intOpenLightAdds, mainDeviceId);
		} else {
			openCmdl = "";
		}
	}
}
